package com.bac.rentmap.map.thumbnail;

import java.util.Map;

import org.springframework.beans.factory.annotation.Required;

public class MapThumbnailService {
    public static final int THUMBNAIL_SIZE = 110;
    private Map<String, ThumbnailBean> thumbnailBeans;
    
    public Point calculateThumbnailCoordinates(String city, double lon, double lat){
        ThumbnailBean thumbnailBean = thumbnailBeans.get(city);
        if(thumbnailBean == null)
            return null;
        return new Point(
                translate(thumbnailBean.getMinLon(), thumbnailBean.getMaxLon(), lon),
                translate(thumbnailBean.getMinLat(), thumbnailBean.getMaxLat(), lat)
                );
    }
    
    private int translate(double minCoordinate, double maxCoordinate, double actualCoordinate){
        return (int) (THUMBNAIL_SIZE * (actualCoordinate - minCoordinate) / (maxCoordinate - minCoordinate));
    }

    @Required
    public void setThumbnailBeans(Map<String, ThumbnailBean> thumbnailBeans) {
        this.thumbnailBeans = thumbnailBeans;
    }
}
